<?php
// use Illuminate\Support\Facades\Schema;
use Jialeo\LaravelSchemaExtend\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateAuthsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        // 管理员表
        Schema::create('auth_admin', function (Blueprint $table) {
            $table->comment = '管理员表';
            $table->increments('id')->comment('管理员ID');
            $table->char('name', 100)->default('')->comment('名称');
            $table->char('phone', 100)->default('')->comment('手机号');
            $table->char('username', 50)->unique()->default('')->comment('账号');
            $table->char('password')->default('')->comment('密码');
            $table->integer('group_id')->default(0)->comment('权限组ID');
            $table->integer('project_id')->default(0)->comment('项目ID');
            $table->tinyInteger('status')->default(1)->comment('状态:0=禁用,1=启用');
            $table->timestamp('created_at')->nullable()->comment('创建时间');
            $table->timestamp('updated_at')->nullable()->comment('更新时间');
        });
        // 权限组表
        Schema::create('auth_group', function (Blueprint $table) {
            $table->comment = '权限组表';
            $table->increments('id')->comment('权限组ID');
            $table->char('name', 100)->unique()->default('')->comment('权限组名称');
            $table->string('content', 100)->nullable()->default('')->comment('描述');
            $table->tinyInteger('status')->default(1)->comment('状态:0=禁用,1=启用');
            $table->longtext('rules')->nullable()->comment('权限规则多个用|隔开');
            $table->timestamp('created_at')->nullable()->comment('创建时间');
            $table->timestamp('updated_at')->nullable()->comment('更新时间');
        });
        // 权限列表
        Schema::create('auth_rule', function (Blueprint $table) {
            $table->comment = '权限表';
            $table->increments('id')->comment('权限列表ID');
            $table->string('path', 100)->nullable()->default('')->comment('标识');
            $table->string('url', 100)->nullable()->default('')->comment('路由文件');
            $table->string('redirect', 100)->nullable()->default('')->comment('重定向路径');
            $table->char('name', 100)->default('')->comment('权限名称');
            $table->tinyInteger('type')->default(1)->comment('菜单类型:1=模块,2=目录,3=菜单');
            $table->tinyInteger('status')->default(1)->comment('侧边栏显示状态:0=隐藏,1=显示');
            $table->tinyInteger('auth_open')->default(1)->comment('是否验证权限:0=否,1=是');
            $table->tinyInteger('level')->default(1)->comment('级别');
            $table->tinyInteger('affix')->default(0)->comment('是否固定面板:0=否,1=是');
            $table->string('icon', 50)->nullable()->default('')->comment('图标名称');
            $table->integer('pid')->default(0)->comment('父级ID');
            $table->integer('sort')->default(1)->comment('排序');
            $table->timestamp('created_at')->nullable()->comment('创建时间');
            $table->timestamp('updated_at')->nullable()->comment('更新时间');
        });
        // 附件表
        Schema::create('auth_attachment', function (Blueprint $table) {
            $table->comment = '图片表';
            $table->increments('id')->comment('图片ID');
            $table->string('url', 150)->default('')->comment('图片路径');
            $table->tinyInteger('status')->default(1)->comment('状态:0=已删除,1=应用中');
            $table->tinyInteger('open')->default(1)->comment('类型:1=本地,2=七牛云');
            $table->timestamp('created_at')->nullable()->comment('创建时间');
            $table->timestamp('updated_at')->nullable()->comment('更新时间');
        });
        // 系统配置表
        Schema::create('auth_config', function (Blueprint $table) {
            $table->comment = '系统配置表';
            $table->increments('id')->comment('系统配置ID');
            $table->char('name', 100)->default('')->comment('站点名称');
            $table->tinyInteger('image_status')->nullable()->comment('图片储存:1=本地,2=七牛云');
            $table->integer('logo_id')->nullable()->comment('站点logo');
            $table->text('about_us')->nullable()->comment('关于我们');
            $table->timestamp('created_at')->nullable()->comment('创建时间');
            $table->timestamp('updated_at')->nullable()->comment('更新时间');
        });
        // 地区表
        Schema::create('auth_areas', function (Blueprint $table) {
            $table->comment = '地区表';
            $table->increments('id')->comment('地区表ID');
            $table->integer('pid')->default(0)->comment('父级ID');
            $table->char('name', 50)->default('')->comment('名称');
            $table->char('short_name', 50)->default('')->comment('简称');
            $table->tinyInteger('level_type')->default(1)->comment('级别');
            $table->integer('city_code')->nullable()->comment('区号');
            $table->integer('zip_code')->nullable()->comment('邮编');
            $table->string('lng', 50)->nullable()->comment('经度');
            $table->string('lat', 50)->nullable()->comment('纬度');
            $table->string('pinyin', 50)->nullable()->comment('拼音');
            $table->tinyInteger('status')->default(1)->comment('显示状态:0=隐藏,1=显示');
            $table->integer('sort')->default(1)->comment('排序');
            $table->timestamp('created_at')->nullable()->comment('创建时间');
            $table->timestamp('updated_at')->nullable()->comment('更新时间');
        });
        // 操作日志表
        Schema::create('auth_operation_logs', function (Blueprint $table) {
            $table->comment = '操作日志表';
            $table->increments('id')->comment('操作日志ID');
            $table->string('content', 200)->default('')->comment('操作描述');
            $table->string('url', 200)->default('')->comment('操作路由');
            $table->string('method', 10)->default('')->comment('请求方式');
            $table->string('ip', 100)->default('')->comment('请求ip');
            $table->integer('admin_id')->nullable()->comment('管理员id');
            $table->longtext('data')->nullable()->comment('请求数据');
            $table->longtext('header')->nullable()->comment('请求header');
            $table->timestamp('created_at')->nullable()->comment('操作时间');
            $table->timestamp('updated_at')->nullable()->comment('更新时间');
        });
        // 平台项目表
        Schema::create('auth_projects', function (Blueprint $table) {
            $table->comment = '平台项目表';
            $table->increments('id')->comment('项目ID');
            $table->char('name', 100)->default('')->comment('项目名称');
            $table->integer('logo_id')->nullable()->comment('站点logo');
            $table->integer('ico_id')->nullable()->comment('站点标识');
            $table->string('url', 100)->default('')->comment('项目地址');
            $table->string('description')->default('')->comment('项目描述');
            $table->string('keywords')->default('')->comment('项目关键词');
            $table->tinyInteger('status')->default(1)->comment('状态:0=禁用,1=启用');
            $table->timestamp('created_at')->nullable()->comment('创建时间');
            $table->timestamp('updated_at')->nullable()->comment('更新时间');
        });
        // 平台用户表
        Schema::create('auth_users', function (Blueprint $table) {
            $table->comment = '平台用户表';
            $table->increments('id')->comment('用户ID');
            $table->char('name', 100)->default('')->comment('姓名');
            $table->char('nickname', 100)->default('')->comment('昵称');
            $table->char('phone', 100)->unique()->default('')->comment('手机号');
            $table->char('email', 50)->unique()->default('')->comment('邮箱');
            $table->char('password')->default('')->comment('密码');
            $table->integer('province_id')->nullable()->comment('省ID');
            $table->integer('city_id')->nullable()->comment('市ID');
            $table->integer('county_id')->nullable()->comment('区县ID');
            $table->tinyInteger('status')->default(1)->comment('状态:0=拉黑,1=正常');
            $table->tinyInteger('sex')->default(0)->comment('性别:0=未知,1=男，2=女');
            $table->string('birth', 20)->default('')->comment('出生年月日');
            $table->timestamp('created_at')->nullable()->comment('创建时间');
            $table->timestamp('updated_at')->nullable()->comment('更新时间');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('auth_admin');
        Schema::dropIfExists('auth_group');
        Schema::dropIfExists('auth_rule');
        Schema::dropIfExists('auth_attachment');
        Schema::dropIfExists('auth_config');
        Schema::dropIfExists('auth_areas');
        Schema::dropIfExists('auth_operation_logs');
        Schema::dropIfExists('auth_projects');
        Schema::dropIfExists('auth_users');
    }
}
